package cn.tedu.coolshark.mapper;

import cn.tedu.coolshark.entity.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductMapper {
    //0代表浏览量
    @Insert("insert into product values (null,#{title},#{url},#{price},#{oldPrice},0,#{saleCount},#{created},#{categoryId})")
    void insert(Product product);
    @Select("select id,title,price,sale_count,url from product")
    @Result(property = "saleCount",column = "sale_Count")
    List<Product> select();
    @Delete("delete from product where id=#{id}")
    void deleteById(int id);
    @Select("select url from product where id=#{id}")
    String selectById(int id);
    @Select("select id,title,url,price,old_price,sale_count from product")
    @Result(property = "saleCount",column = "sale_count")
    @Result(property = "oldPrice",column = "old_price")
    List<Product> selectIndex();
    @Select("select id,title,sale_count from product order by sale_count desc limit 0,6")
    @Result(property = "saleCount",column = "sale_count")
    List<Product> selectTop();
    @Select("select id,title,url,price,old_price,sale_count from product where category_id=#{cid}")
    @Result(property = "saleCount",column = "sale_count")
    @Result(property = "oldPrice",column = "old_price")
    List<Product> selectByCid(int cid);
}
